package com.nantai.jiafang.nantaijiafang.activity.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.ViewGroup;


import com.nantai.jiafang.nantaijiafang.R;
import com.nantai.jiafang.nantaijiafang.bean.EveryDayBean;
import com.nantai.jiafang.nantaijiafang.bean.ProductionOrderInfo;
import com.nantai.jiafang.nantaijiafang.databinding.ItemMianliaoEverydayBinding;

import java.util.ArrayList;
import java.util.List;

import static android.content.ContentValues.TAG;

/**
 * Created by admin on 2017/11/25.
 */

public class MiaoliaoEveryDayAdapter extends RecyclerView.Adapter<MiaoliaoEveryDayAdapter.AdapterHolder> {
    private Context mContext;
    private static List<EveryDayBean> mDataList;
    private  List<EveryDayBean> levels;
    private  String cutarea="";
    private String level="";
    public MiaoliaoEveryDayAdapter(Context context, List<EveryDayBean> list) {
        this.mContext = context;
        this.mDataList = list;
        levels=new ArrayList<>(list);
    }

    @Override
    public AdapterHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemMianliaoEverydayBinding binding= DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.item_mianliao_everyday,parent,false);
        return new AdapterHolder(binding);
    }
    @Override
    public void onBindViewHolder(AdapterHolder holder, int position) {
        holder.getmBinding().setMianLiaoEveryDay(levels.get(position));
        holder.getmBinding().executePendingBindings();

    }

    @Override
    public int getItemCount() {
        return levels == null ? 0 :levels.size();
    }

    static class AdapterHolder extends RecyclerView.ViewHolder {
        // 创建一个静态获取方法
      /*  static AdapterHolder create(LayoutInflater inflater, ViewGroup parent) {
            FragmentUperrorItemBinding binding = FragmentUperrorItemBinding.inflate(inflater, parent, false);
            return new AdapterHolder(binding);
        }*/
        private ItemMianliaoEverydayBinding mBinding;

        private AdapterHolder(ViewDataBinding binding) {
            super(binding.getRoot());
            this.mBinding = (ItemMianliaoEverydayBinding)binding;
        }
        public ItemMianliaoEverydayBinding getmBinding(){
            return mBinding;
        }
    }

    public void levels_select(int code){
        switch (code){
            case 0:
                level="";
                levels.clear();
                for (EveryDayBean item:
                     mDataList) {
                    if (cutarea.equals("")||item.getCutArea().equals(cutarea)){
                        levels.add(item);
                    }
                }
                levels.addAll(mDataList);
                break;
            case 1:
                levels.clear();
                level="A";
                for (EveryDayBean everyDayBean:
                     mDataList) {
                    if (everyDayBean.getLevels().equals("A") && (cutarea.equals("") || everyDayBean.getCutArea().equals(cutarea))){
                        levels.add(everyDayBean);
                    }
                }
                break;
            case 2:
                level="B";
                levels.clear();
                for (EveryDayBean everyDayBean:
                        mDataList) {
                    if (everyDayBean.getLevels().equals("B") && (cutarea.equals("") || everyDayBean.getCutArea().equals(cutarea))){
                        levels.add(everyDayBean);
                    }
                }
                break;
        }
        notifyDataSetChanged();
    }
    //厂区全部显示
    public void showall(){
        cutarea="";
        levels.clear();
        for (EveryDayBean item:
                mDataList) {
            //等级筛选
            if (level.equals("")|| item.getLevels().equals(level)){
                Log.e(TAG, "showall: " );
                levels.add(item);
            }
        }
        notifyDataSetChanged();
    }
    //厂区选择
    public void showselect(String name){
        Log.e("xuxin","name = "+name);
        cutarea=name;
        levels.clear();
        for (EveryDayBean item:
                mDataList) {
            if (item.getCutArea().equals(name) && (level.equals("") || item.getLevels().equals(level)) ){
                levels.add(item);
            }
        }
        notifyDataSetChanged();
    }
}